layui.config({
    base: "static/layui/module/"
}).extend({
	dynamicCondition: 'dynamicCondition/dynamicCondition',
}).use(['form','layer','jquery','table','laydate','upload','element','dynamicCondition'],function(){
	var form = layui.form,
		layer = layui.layer,
        laypage = layui.laypage,
        $ = layui.jquery,
        table=layui.table,
        upload = layui.upload,
        laydate =layui.laydate,
        element = layui.element,
        dynamicCondition=layui.dynamicCondition;

	table.render({
		elem: '#table'
		,title: '列表'
		,url:'/manage/report/all/list'
		,method: 'post'
		,cols: [
			[
				{ field: "person_name", title: "市场专员", minWidth: 150 },
				{ field: "ywlx", title: "业务类型", minWidth: 150 },
				{ field: "customer_name", title: "客户公司", minWidth: 150 },
				{ field: "purchase_person", title: "客户外采人员", minWidth: 150 },
				{ field: "type", title: "订单类别", minWidth: 150 },
				{ field: "cplb", title: "产品类别", minWidth: 150 },
				{ field: "order_no", title: "内部订单号",minWidth: 150  },
				{ field: "customer_order", title: "客户订单号", minWidth: 150 },
				{ field: "cinvname", title: "产品型号", minWidth: 150 },
				{ field: "cbatch", title: "客户批次", minWidth: 150 },
				{ field: "order_qty", title: "数量", minWidth: 150 },
				{ field: "sfsw", title: "有无实物",minWidth: 150  },
				{ field: "order_process_name", title: "工序", minWidth: 150 },
				{ field: "llrq", title: "来料日期", minWidth: 150 },
				{ field: "dispatch_qty", title: "出货数量", minWidth: 150 },
				{ field: "quality_qty", title: "合格数量", minWidth: 150 },
				{ field: "unquality_qty", title: "不合格数量", minWidth: 150 },
				{ field: "stock_qty", title: "库存数量", minWidth: 150 },
				{ field: "producting_qty", title: "在制数量", minWidth: 150 },
				{ field: "memo", title: "备注", minWidth: 150 },
				{ field: "special_memo", title: "特殊备注", minWidth: 150 },
				{ field: "czjslx", title: "计价单位", minWidth: 150 },
				{ field: "settle_qty", title: "结算数值", minWidth: 150 },
				{ field: "ioritaxcost", title: "单价", minWidth: 150 },
				{ field: "order_amount", title: "承揽金额", minWidth: 150 },
				{ field: "settle_amount", title: "产出金额", minWidth: 150 },
				{ field: "account", title: "是否对账", minWidth: 150, templet: function(d) {
						return d.account ? '是' : '否';}
				},
				{ field: "htbh", title: "合同编号", minWidth: 150 },
				{ field: "htje", title: "合同金额", minWidth: 150 },
				{ field: "htqdrq", title: "签订合同日期", minWidth: 150 },
				{ field: "fph", title: "发票号", minWidth: 150 },
				{ field: "fpje", title: "开票金额", minWidth: 150 },
				{ field: "kprq", title: "开票日期", minWidth: 150 },
				{ field: "ljskje", title: "累计收款金额", minWidth: 150 },
				{ field: "hkrq", title: "回款日期", minWidth: 150 },
				{ field: "cls", title: "承揽商", minWidth: 150 }
			]
		]
		,page: true
		,limit: 15
		,limits: [15,30,40,50,60,70,80,90,100,200]
		,height: 'full-120'
		,toolbar:'#tableToolbar'
		,defaultToolbar: ['filter']
		,text: {
			none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
		}
		,data: []
		,done: function (res, curr, count){
		}
	})


	var dataFields = [
		{field:"person_name", title:"市场专员", edit:"text"}
		,{field:"ywlx", title:"业务类型", edit:"text"}
		,{field:"customer_name", title:"客户公司", edit:"text"}
		,{field:"purchase_person", title:"客户外采人员", edit:"text"}
		,{field:"type", title:"订单类别", edit:"text"}
		,{field:"cplb", title:"产品类别", edit:"text"}
		,{field:"order_no", title:"内部订单号", edit:"text"}
		,{field:"customer_order", title:"客户订单号", edit:"text"}
		,{field:"cinvname", title:"产品型号", edit:"text"}
		,{field:"cbatch", title:"客户批次", edit:"text"}
	];
	var top_dc = undefined;
	var dc = dynamicCondition.create({
    	fields:dataFields
	  	,tableId:"table" 
		,conditionTextId:"#findMsg"
		,type:"complex" 
	  	,requestDataType:"json"
	  	,counts:5
		,queryCallBack:function(requestData){
		}
		,afterOpen: function (_dc) {
			top_dc = _dc;
		}
	});
	
    table.on('toolbar(table)', function(obj){
		switch(obj.event){
			case 'find':
				dc.open();
				break;
			case 'download':
				layer.confirm('确定要导出数据并下载到本地吗？', function (index) {
					var conditionArray = new Array();
					if (top_dc != undefined) {
						for (let i in top_dc.cacheCondition) {
							if (top_dc.cacheCondition[i].conditionValueLeftVal.value != ''
								|| top_dc.cacheCondition[i].conditionValueRightVal.value != '' || top_dc.cacheCondition[i].conditionValueVal.value != '') {
								var condition = {
									field: top_dc.cacheCondition[i].conditionFieldVal
									,title: top_dc.data[i].title
									,type: top_dc.cacheCondition[i].conditionOptionVal
									,right: top_dc.cacheCondition[i].conditionValueRightVal.value
									,left: top_dc.cacheCondition[i].conditionValueLeftVal.value
									,value: top_dc.cacheCondition[i].conditionValueVal.value
								}
								conditionArray.push(condition);
							}
						}
					}
					window.location.href = "/manage/report/download/sale_settle?condition=" + encodeURI(JSON.stringify(conditionArray));
					layer.close(index);
				});
				break;
		};
	});
})
